<%--
  Created by IntelliJ IDEA.
  User: 老头
  Date: 2023/3/29
  Time: 18:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <%@page import="java.sql.*"%>
    <%
        ResultSet rs = null;
        Statement stmt = null;
        Connection conn = null;
        out.print("开始");
        try{
            Class.forName("com.mysql.jdbc.Driver");//加载驱动程序
            //“maiba”为数据库名，“root”为数据库登录账号，“123456”为数据库登录密码
            conn = DriverManager.getConnection
                    ("jdbc:mysql://localhost:3306/maiba?serverTimezone=CST","root","123456");
            stmt = conn.createStatement();
            rs = stmt.executeQuery("select * from product");//查询整个用户表数据
            while(rs.next()){//遍历整个表数据
                out.print("<BR>");
                out.print("  id：" + rs.getInt(1));
                out.print(";  书名：" + rs.getString(2));
                out.print(";  书名：" + rs.getString(3));
                out.print("<BR>");
            }

            rs = stmt.executeQuery("select * from product where product_id = 1");//查询整个用户表数据
            while(rs.next()){//遍历整个表数据
                out.print("<BR>");
                out.print("条件查询");
                out.print("<BR>");
                out.print("  id：" + rs.getInt(1));
                out.print(";  书名：" + rs.getString(2));
                out.print(";  价格：" + rs.getString(3));
                out.print("<BR>");
            }

            stmt.execute("insert into product(product_id,product_name, product_inventory, product_price) values(5,'老猪',0,0)");
            rs = stmt.executeQuery("select * from product");
            while(rs.next()){//遍历整个表数据
                out.print("<BR>");
                out.print("插入");
                out.print("<BR>");
                out.print("  id：" + rs.getInt(1));
                out.print(";  书名：" + rs.getString(2));
                out.print(";  价格：" + rs.getString(3));
                out.print("<BR>");
            }
        }catch(Exception e){
            e.printStackTrace();
        }finally {
            if (rs != null)
                rs.close();
            if (stmt != null)
                stmt.close();
            if (conn != null)
                conn.close();
        }
    %>

</head>
<body>

</body>
</html>
